from Controller.BaseController import BaseController
from Utility import ParameterKey
from Common.QuestionFormTemplate import QuestionFormTemplate


class GetQuestionTemplateController(BaseController):
    def get(self):
        """
        Load HIT Question template object according to user select
        It take a query string "hpid"
        """
        u = self.GetCurrentUser()
        if u is None:
            self.response.out.write("Click here to <a href='/login/re?/create/hit'>login</a> now.")
            return

        hp_id = self.request.get(ParameterKey.HIT_Template_ID)
        if hp_id is not None:
            # Load HIT Properties object according to this id
            # serialize HIT Properties Template object to JSON string
            hitQuestionFormTemplate = QuestionFormTemplate.get(hp_id)
            template_values = {'HITQuestionTemplates': u.Ref_Company.QuestionFormTemplates, 'questionFormTemplate': hitQuestionFormTemplate}
            self.Render("createhitstep/step3", template_values)
        else:
            # return error message
            self.response.write("You did not enter right question form id")
